Letter Combinations of a Phone Number
Medium
Question
You are given a string of digits from 2-9 (inclusive), where each digit is mapped to letters based on this phone keypad layout:
Generate all unique combinations of letters that can be formed by pressing these digits on the keypad.
Input: digits = "65"
Output: ["mj", "mk", "ml", "nj", "nk", "nl", "oj", "ok", "ol"]
4 can represent "m", "n", or "o" while 5 can represent "j", "k", or "l".
Input: digits = "9"
Output: ["w", "x", "y", "z"]
4 can represent "w", "x", "y", "z".
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
How many unique combinations are there when digits = "59"?
5
7
9
12
Take a moment to understand the problem and think of your approach before you start coding.